/*
 *      Author: Guannan Ma
 *      @mythmgn
 *      Whatever license applied
 */

#include <stdio.h>
#include <stdlib.h>

#include "base.h"

#ifndef BASE_LIB_LIBSTACK_H
#define BASE_LIB_LIBSTACK_H

#ifdef	__cplusplus

extern "C" {
#endif

typedef struct stackNode {
	void *value;
} stackNode;

typedef struct stack {
	int now;
	int maxsize;
	int autoExtend;
	/*
	 When the mark s->now is -1,
	 the pointed stack has no item.
	 When now =maxsize-1, the stack is full.
	 */
	stackNode *content;
    struct mlock *p_mlock;

} stack;

/**
 * @brief Initialize the stack
 *
 * @param [in/out] slots   : int
 * @param [in/out] autoExtend   : int
 * @return  stack* 
 * @retval  On error, return NULL. Otherwise, return a stack pointer.
 * @note  This is not a thread_safe initialization. Use initStack_r for thread_safe use.
 * @author maguannan
 * @date 2013/01/28 17:13:35
**/
stack* initStack(int slots, int autoExtend);

/**
 * @brief Initialize the stack. And it's the thread_safe init.
 *
 * @param [in/out] slots   : int
 * @param [in/out] autoExtend   : int
 * @param [in/out] thd_safe   : BOOL
 * @return  stack* 
 * @retval  On error, return NULL. Otherwise, return a stack pointer.
 * @note    Thread-safe initialization
 * @author maguannan
 * @date 2013/01/28 17:15:02
**
stack* initStack_r(int slots, int autoExtend, BOOL thd_safe);
*/

int push_in(void *p, stack *s);
void * pop_up(stack *s);
BOOL isStackFull(stack *s);
BOOL isStackEmpty(stack *s);
BOOL freeStack(stack *s);

#ifdef	__cplusplus
}
#endif

#endif // LIB_STACK_H_INCLUDED
